<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link href="<%=request.getContextPath() %>/ext/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath() %>/ext/ext-all.js"></script>
</head>
<script type="text/javascript">
	function sexRender(value, cellmeta, record, rowIndex, columnIndex, store){
		if ( value == "0" )
			value = "女";
		if ( value == "1" )
			value = "男";
		return value;
	}
	function statusRender(value, cellmeta, record, rowIndex, columnIndex, store){
		if ( value == "0" )
			value = "离职";
		if ( value == "1" )
			value = "在职";
		return value;
	}
	Ext.onReady(function(){
		var itemsPerPage = 10;
		var store=new Ext.data.Store({ 
			pageSize: itemsPerPage, 
			fields : [
				'dbid',
				'name',
				'password',
				'department.name',
				'refDepartmentId',
				'shop.name',
				'refShopId',
				{ name: 'birthday' , type : 'date' },
				'sex',
				'hometown',
				'tele',
				'mobile',
				'status',
				{ name: 'createDate' , type : 'date' },
    		],
    		proxy : {  
   				type : 'ajax', 
				url : '<%=request.getContextPath() %>/employee/listEmployee.action',
   				reader : { type : 'json',root : 'employeePageBeans' ,totalProperty: 'totalProperty'}   
    		} , 
			autoLoad : false,  
   			timeout: 900000,
		}); 
		var gridPanel= Ext.create('Ext.grid.GridPanel', {
 			store: store,    
			selModel : Ext.create('Ext.selection.CheckboxModel',{   mode: 'SINGLE' }),
			columnLines: true,
			columns: [
					{ text :'dbid', flex : 1 , sortable : true , hidden : true , dataIndex :'dbid' },
					{ text :'名字', flex : 1 , sortable : true , dataIndex :'name' },
// 					{ text :'password', flex : 1 , sortable : true , dataIndex :'password' },
					{ text :'部门', flex : 1 , sortable : true , dataIndex :'department.name' },
					{ text :'门市', flex : 1 , sortable : true , dataIndex :'shop.name' },
					{ text :'refDepartmentId', flex : 1 , sortable : true , hidden : true , dataIndex :'refDepartmentId' },
					{ text :'refShopId', flex : 1 , sortable : true , hidden : true , dataIndex :'refShopId' },
					{ text :'生日', flex : 1 , sortable : true , dataIndex :'birthday' , renderer:Ext.util.Format.dateRenderer('Y-m-d'), },
					{ text :'性别', flex : 1 , sortable : true , dataIndex :'sex' ,renderer : sexRender },
					{ text :'籍贯', flex : 1 , sortable : true , dataIndex :'hometown' },
					{ text :'电话', flex : 1 , sortable : true , dataIndex :'tele' },
					{ text :'手机', flex : 1 , sortable : true , dataIndex :'mobile' },
					{ text :'状态', flex : 1 , sortable : true , dataIndex :'status' ,renderer : statusRender},
// 					{ text :'入录日期', flex : 1 , sortable : true , dataIndex :'createDate' , renderer:Ext.util.Format.dateRenderer('Y-m-d'), },
			],
			height: 350,
			width: 600,
			tbar: new Ext.Toolbar({
				height : '32' , autoWidth:true, autoShow:true,
				items:[
				{ xtype: 'button', text: '新增',tooltip: 'Add New Row',
					handler:  function (){
						var popWindow = new Ext.Window({
							id : 'AddEmployeeWindow',
				    		width : 600,
				    		title : '新增一条记录.', 
				    		closable: true, 
				    		resizable: true,
				    		constrainHeader: true,
				    		modal: true,
				    	    plain: true, 
				    		layout : 'fit',
				    		x : 250, y : 100,
				    		items :[{
				    			xtype: 'form',
				    			layout: 'form',
				    			frame: true,
				    			bodyPadding: '2 2 0',
				    			fieldDefaults: {
				    				msgTarget: 'side',
				    				labelWidth: 75
				    			},
				    			defaultType: 'textfield',
				    			items :[
				    			 { 
				    					xtype: 'textfield',
				    					fieldLabel: '名字',
				    					name: 'name',
				    					id: 'name',
				    			 }, 
				    			 { 
				    					xtype: 'textfield',
				    					fieldLabel: '密码',
				    					name: 'password',
				    					id: 'password',
				    					value : '12345678',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/department/listDepartment.action', reader : { type : 'json' , root : 'departmentPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : true , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: '部门',
				    					name: 'refDepartmentId',
				    					id: 'refDepartmentId',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/shop/listShop.action', reader : { type : 'json' , root : 'shopPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : true , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: '门市',
				    					name: 'refShopId',
				    					id: 'refShopId',
				    			 }, 
				    			 { 
				    					xtype: 'datefield',
				    					format: 'Y-m-d H:i:s',
				    					fieldLabel: '生日',
				    					name: 'birthday',
				    					id: 'birthday',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					fieldLabel: '性别',
				    					name: 'sex',
				    					id: 'sex',
										store: { 
											xtype :'Ext.data.Store',proxy :{ type:'memory' } ,
											model:  Ext.define('sex',{ extend: 'Ext.data.Model',fields: ['dbid','name'] } ),
											data: [{"dbid":"1","name":"男"},{"dbid":"0","name":"女"}]    
										},
					   					valueField:'dbid', 
										displayField:'name',
				    			 }, 
				    			 { 
				    					xtype: 'textfield',
				    					fieldLabel: '籍贯',
				    					name: 'hometown',
				    					id: 'hometown',
				    			 }, 
				    			 { 
				    					xtype: 'textfield',
				    					fieldLabel: '电话',
				    					name: 'tele',
				    					id: 'tele',
				    			 }, 
				    			 { 
				    					xtype: 'textfield',
				    					fieldLabel: '手机',
				    					name: 'mobile',
				    					id: 'mobile',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					fieldLabel: '状态',
				    					name: 'status',
				    					id: 'status',
										store: { 
											xtype :'Ext.data.Store',proxy :{ type:'memory' } ,
											model:  Ext.define('status',{ extend: 'Ext.data.Model',fields: ['dbid','name'] } ),
											data: [{"dbid":"1","name":"正常"},{"dbid":"0","name":"离职"}]    
										},
					   					valueField:'dbid', 
										displayField:'name',
				    			 }, 
				    			 { 
				    					xtype: 'datefield',
				    					format: 'Y-m-d H:i:s',
				    					fieldLabel: 'createDate',
				    					name: 'createDate',
				    					id: 'createDate',
				    					value : new Date(),
				    					hidden : true 
				    			 }, 
				    			],
				    			 buttons :[
				    			 { 
				    					xtype: 'button',
				    					text: '保存',
				    					name: 'SaveAddBtn',
				    					id: 'SaveAddBtn',
				    					handler:  function (){ 
				    						     this.up('form').getForm().doAction('submit',{ 
				    					             url:'<%=request.getContextPath() %>/employee/insertEmployee.action', 
				    					             method:'post', 
				    					             params:'', 
				    					             success:function(form,action){ 
				    					                 Ext.Msg.alert('新增成功',action.result.info); 
				    					                 popWindow.close(); 
				    					                 store.reload(); 
				    					             }, 
				    					             failure:function(e){ 
				    					                  Ext.Msg.alert('error','Fail'); 
				    					             } 
				    					           }); 
				    					},
				    			 }, 
				    			 { 
				    					xtype: 'button',
				    					text: '重置',
				    					name: 'ResetAddBtn',
				    					id: 'ResetAddBtn',
				    					handler:  function (){  this.up('form').getForm().reset();},
				    			 }, 
				    			 { 
				    					xtype: 'button',
				    					text: '关闭',
				    					name: 'CloseAddBtn',
				    					id: 'CloseAddBtn',
				    					handler:  function (){  popWindow.close();},
				    			 }, 
				    			 ] 
				    		}]
				    	});
						popWindow.show();
					}
				} ,
				{ xtype: 'button', text: '更新',tooltip: 'Update Row',
					handler:  function (){
						var grid = this.ownerCt.ownerCt; 
						var checkRecord = grid.getSelectionModel().getSelection(); 
						if (checkRecord.length != 0) {
							var popWindow = new Ext.Window({
								id : 'updateWindow',
				    			width : 600,
				    			title : '更新记录.', 
				    			closable: true, 
				    			resizable: true,
				    			constrainHeader: true,
				    			modal: true,
				    	   		plain: true, 
				    			layout : 'fit',
				    			x : 250, y : 100,
				    			items :[{
				    				xtype: 'form',
				    				id: 'updateForm',
				    				layout: 'form',
				    				frame: true,
				    				bodyPadding: '2 2 0',
				    				fieldDefaults: {
				    					msgTarget: 'side',
				    					labelWidth: 75
				    				},
				    				defaultType: 'textfield',
				    			items :[
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: '编号', hidden :true ,
				    					name: 'dbid',
				    					id: 'dbid',
				    					readOnly: true,
				    			 }, 
				    			 { 
				    					xtype: 'textfield',
				    					fieldLabel: '姓名',
				    					name: 'name',
				    					id: 'name',
				    			 }, 
				    			 { 
				    					xtype: 'textfield',
				    					fieldLabel: '密码',
				    					name: 'password',
				    					id: 'password',
				    					hidden : true
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/department/listDepartment.action', reader : { type : 'json' , root : 'departmentPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : false, , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: '部门',
				    					name: 'refDepartmentId',
				    					id: 'refDepartmentId',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/shop/listShop.action', reader : { type : 'json' , root : 'shopPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : false, , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: '门市',
				    					name: 'refShopId',
				    					id: 'refShopId',
				    			 }, 
				    			 { 
				    					xtype: 'datefield',
				    					format: 'Y-m-d H:i:s',
				    					fieldLabel: '生日',
				    					name: 'birthday',
				    					id: 'birthday',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					fieldLabel: '性别',
				    					name: 'sex',
				    					id: 'sex',
										store: { 
											xtype :'Ext.data.Store',proxy :{ type:'memory' } ,
											model:  Ext.define('sex',{ extend: 'Ext.data.Model',fields: ['dbid','name'] } ),
											data: [{"dbid":"1","name":"男"},{"dbid":"0","name":"女"}]    
										},
					   					valueField:'dbid', 
										displayField:'name',
				    			 }, 
				    			 { 
				    					xtype: 'textfield',
				    					fieldLabel: '祖籍',
				    					name: 'hometown',
				    					id: 'hometown',
				    			 }, 
				    			 { 
				    					xtype: 'textfield',
				    					fieldLabel: '电话',
				    					name: 'tele',
				    					id: 'tele',
				    			 }, 
				    			 { 
				    					xtype: 'textfield',
				    					fieldLabel: '手机',
				    					name: 'mobile',
				    					id: 'mobile',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					fieldLabel: '状态',
				    					name: 'status',
				    					id: 'status',
										store: { 
											xtype :'Ext.data.Store',proxy :{ type:'memory' } ,
											model:  Ext.define('status',{ extend: 'Ext.data.Model',fields: ['dbid','name'] } ),
											data: [{"dbid":"1","name":"正常"},{"dbid":"0","name":"离职"}]    
										},
					   					valueField:'dbid', 
										displayField:'name',
				    			 }, 
				    			 { 
				    					xtype: 'datefield',
				    					format: 'Y-m-d H:i:s',
				    					fieldLabel: 'createDate',
				    					name: 'createDate',
				    					id: 'createDate',
				    					hidden : true
				    			 }, 
				    			],
				    			 buttons :[
				    			 { 
				    					xtype: 'button',
				    					text: '保存',
				    					name: 'SaveUppdateBtn',
				    					id: 'SaveUppdateBtn',
				    					handler:  function (){ 
				    						     this.up('form').getForm().doAction('submit',{ 
				    					             url:'<%=request.getContextPath() %>/employee/updateEmployee.action', 
				    					             method:'post', 
				    					             params:'', 
				    					             success:function(form,action){ 
				    					                 Ext.Msg.alert('更新成功',action.result.info); 
				    					                 popWindow.close(); 
				    					                 store.reload(); 
				    					             }, 
				    					             failure:function(e){ 
				    					                  Ext.Msg.alert('error','Fail'); 
				    					             } 
				    					           }); 
				    					},
				    			 }, 
				    			 { 
				    					xtype: 'button',
				    					text: '重置',
				    					name: 'ResetUpdateBtn',
				    					id: 'ResetUpdateBtn',
				    					handler:  function (){  this.up('form').getForm().reset();},
				    			 }, 
				    			 { 
				    					xtype: 'button',
				    					text: '关闭',
				    					name: 'CloseAddBtn',
				    					id: 'CloseAddBtn',
				    					handler:  function (){  popWindow.close();},
				    			 }, 
				    			 ] 
				    			}]
				    		});
							popWindow.show();
							Ext.getCmp("updateForm").getForm().loadRecord(checkRecord[0]);
							 Ext.getCmp("updateForm").getForm().findField("refDepartmentId").setValue( checkRecord[0].data["refDepartmentId"]);
					 
							Ext.getCmp("updateForm").getForm().findField("refShopId").setValue( checkRecord[0].data["refShopId"]);
						}else{
							Ext.MessageBox.alert('错误提示','请至少选择一条记录?');
				      }
				    }
				} , 
				{ xtype: 'button', text: '删除',tooltip: 'Delete Row',
					handler:  function (){
						var grid = this.ownerCt.ownerCt;
					 Ext.MessageBox.confirm('Confirm', '确定要删除该记录吗?',
							 function showResult(btn,text){
							 	if (btn == "yes"){
									var store = grid.getStore();
									var checkRecord = grid.getSelectionModel().getSelection();
									if (checkRecord.length != 0) {
										Ext.Ajax.request({
											url : '<%=request.getContextPath() %>/employee/deleteEmployee.action',
											params : { dbid : checkRecord[0].data["dbid"] },
											success : function(response, options) {},
										});
										store.remove(checkRecord);
									}else{
										Ext.MessageBox.alert('信息提示','至少选择一条记录!');
				       				}
								}
							}
						);
					}
				}
			] 
		}) ,
		viewConfig : { forceFit : true, scrollOffset : 0 },
		dockedItems: [{ xtype: 'pagingtoolbar', store: store,  dock: 'bottom', displayInfo: true  }],
		title: '员工列表',
		}); 
		var searchPanel = Ext.create('Ext.form.Panel', {
		    defaultType: 'textfield',
			layout: { type: 'column', align: 'stretch',padding: 5 },
			frame: true,
		    items: [{
		    	columnWidth:0.5,
				xtype: 'container',
				flex: 1,
				border:false, 
				layout: 'anchor',
				defaultType: 'textfield',
				items: [
				        {
							xtype : 'textfield',
		   					fieldLabel: '名字',
		   					name: 'qryBeginStringName',
		   					id: 'qryBeginStringName',
		   					anchor:'95%'
				        },
				        {
							xtype: 'combo',
							store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/department/listDepartment.action', reader : { type : 'json' , root : 'departmentPageBeans'} } ,autoLoad: true },
							valueField:'dbid', 
							displayField:'name', 
							fieldLabel: '部门',
		   					anchor:'95%',
		   					name: 'qryBeginIntRefDepartmentId',
		   					id: 'qryBeginIntRefDepartmentId',
				        },
				        {
							xtype : 'datefield',
							format: 'Y-m-d',
		   					fieldLabel: '生日开始日期',
		   					name: 'qryBeginDateBirthday',
		   					id: 'qryBeginDateBirthday',
		   					anchor:'95%'
				        },
				        {
							xtype : 'textfield',
		   					fieldLabel: '祖籍',
		   					name: 'qryBeginStringHometown',
		   					id: 'qryBeginStringHometown',
		   					anchor:'95%'
				        },
				        {
							xtype : 'textfield',
		   					fieldLabel: '手机',
		   					name: 'qryBeginStringMobile',
		   					id: 'qryBeginStringMobile',
		   					anchor:'95%'
				        }
				        /*,
				        {
							xtype : 'datefield',
							format: 'Y-m-d',
		   					fieldLabel: 'CreateDate End',
		   					name: 'qryEndDateCreateDate',
		   					id: 'qryEndDateCreateDate',
		   					anchor:'95%'
				        },
				        */
				]
			},{
				columnWidth:0.5,
				xtype: 'container',
				flex: 1,
				layout: 'anchor', 
				defaultType: 'textfield',
				items: [
				       /* {
							xtype : 'textfield',
		   					fieldLabel: 'Password',
		   					name: 'qryBeginStringPassword',
		   					id: 'qryBeginStringPassword',
		   					anchor:'95%'
				        },*/
				        {
							xtype : 'datefield',
							format: 'Y-m-d',
		   					fieldLabel: '生日截止日期 ',
		   					name: 'qryEndDateBirthday',
		   					id: 'qryEndDateBirthday',
		   					anchor:'95%'
				        },
				        {
				        	xtype: 'combo',			
		   					fieldLabel: '性别',
		   					name: 'qryBeginStringSex',
		   					id: 'qryBeginStringSex',
		   					store: { 
								xtype :'Ext.data.Store',proxy :{ type:'memory' } ,
								model:  Ext.define('sex',{ extend: 'Ext.data.Model',fields: ['dbid','name'] } ),
								data: [{"dbid":"1","name":"男"},{"dbid":"0","name":"女"}]    
		   					},
		   					valueField:'dbid', 
							displayField:'name', 
		   					anchor:'95%'
				        },
				        {
							xtype : 'textfield',
		   					fieldLabel: '电话',
		   					name: 'qryBeginStringTele',
		   					id: 'qryBeginStringTele',
		   					anchor:'95%'
				        },
				        {
				        	xtype: 'combo',			
		   					name: 'qryBeginStringStatus',
		   					id: 'qryBeginStringStatus',
							store: { 
								xtype :'Ext.data.Store',proxy :{ type:'memory' } ,
								model:  Ext.define('status',{ extend: 'Ext.data.Model',fields: ['dbid','name'] } ),
								data: [{"dbid":"1","name":"正常"},{"dbid":"0","name":"离职"}]    
							},
		   					valueField:'dbid', 
							displayField:'name', 
							fieldLabel: '状态',
		   					anchor:'95%',
				        },
				        /*		     
				        {
							xtype : 'datefield',
							format: 'Y-m-d',
		   					fieldLabel: 'CreateDate From',
		   					name: 'qryBeginDateCreateDate',
		   					id: 'qryBeginDateCreateDate',
		   					anchor:'95%'
				        },
				        */
		{
	xtype :'checkbox',
	fieldLabel: '模糊查询',
	name: 'qryLikeEnable',
	id : 'qryLikeEnable',
	anchor:'95%'
}
				]
			}]
			,
			buttons: [{
		        text: '查找',
		        handler: function() {
		            store.load();
		        }
		    },{
		        text: '重置',
		        handler: function() {
		            this.up('form').getForm().reset();
		        }
		    }]
		 });
		store.load({
			params : {
				//username : username,
				start:0 ,
				limit: itemsPerPage 
 			}
		});
 		store.on('beforeload',function(){
	 		Ext.apply(  store.proxy.extraParams, {
				qryLikeEnable : Ext.getCmp("qryLikeEnable").getValue(),
				qryBeginStringName : Ext.getCmp("qryBeginStringName").getValue(),
// 				qryBeginStringPassword : Ext.getCmp("qryBeginStringPassword").getValue(),
				qryBeginIntRefDepartmentId : Ext.getCmp("qryBeginIntRefDepartmentId").getValue(),
				qryBeginDateBirthday : Ext.getCmp("qryBeginDateBirthday").getRawValue(),
				qryEndDateBirthday : Ext.getCmp("qryEndDateBirthday").getRawValue(),
				qryBeginStringSex : Ext.getCmp("qryBeginStringSex").getValue(),
				qryBeginStringHometown : Ext.getCmp("qryBeginStringHometown").getValue(),
				qryBeginStringTele : Ext.getCmp("qryBeginStringTele").getValue(),
				qryBeginStringMobile : Ext.getCmp("qryBeginStringMobile").getValue(),
				qryBeginStringStatus : Ext.getCmp("qryBeginStringStatus").getValue(),
// 				qryBeginDateCreateDate : Ext.getCmp("qryBeginDateCreateDate").getRawValue(),
// 				qryEndDateCreateDate : Ext.getCmp("qryEndDateCreateDate").getRawValue(),
			})
		});
		var mainPanel =Ext.create('Ext.panel.Panel', {
			id : 'employeeMainPanel',
			layout: { type: 'vbox', align: 'stretch',padding: 5 },
			items: [ searchPanel , gridPanel  ],
			renderTo: Ext.getBody(),
		})
	});
</script>
